<?php

class UserMoneyModel extends DBModel
{
	protected $_table = '{{usermoney}}';
	protected $_id = 'userid';
	
	public function addMoney($userid, $howmuch)
	{
		return $this->queryBySql('update ' . $this->getTable() . ' set  howmuch = howmuch + '. $howmuch . ' where userid = ' . $userid);
	}
	
	public function updateMoney($userid, $howmuch)
	{
		return $this->queryBySql('update ' . $this->getTable() . ' set  howmuch = howmuch - '. $howmuch . ' where userid = ' . $userid);
	}
	
	public function getMoney($userid)
	{
		$where['select'] = 'howmuch';
		$where['condition'] = 'userid = :userid';
		$params[':userid'] = $userid;
		return $this->findScalar($where, $params);
	}
}